package org.cncitrus.data.manager;

import org.cncitrus.data.exception.CitrusException;



public class ParamsManager {
	
	static public String Array2String(String[] value){
		StringBuffer sb = new StringBuffer();
		sb.append("(");			
		for(int i=0;i<value.length;i++){
			sb.append("'"+value[i]+"'");
			if(i<value.length-1){
				sb.append(",");
			}
		}
		sb.append(")");
		return sb.toString();
	}
	/**
	 * 把传入参数变为插入格式
	 * @param str
	 * @return
	 * @throws CitrusException
	 */
	static public String getInsertString(String[]... str) throws CitrusException{
		int size = str.length;
		int length = str[0].length;
		StringBuffer sb = new StringBuffer();
		try{
			for(int i=0;i<length;i++){
				StringBuffer tmp = new StringBuffer();
				tmp.append("(");
				for(int j=0;j<size;j++){
					tmp.append("\"");
					tmp.append(str[j][i].replace("\"", "").trim());
					tmp.append("\"");
					if(j<size-1)
						tmp.append(",");
				}
				tmp.append(")");
				
				if(tmp.toString().replace("(", "").replace(")", "").replace("\"", "").replace(",", "").trim().length()!=0){
					sb.append(tmp.toString());					
					sb.append(",");					
				}
			}
		}catch(Exception e){
			throw new CitrusException(e.toString(), e);
		}
		if(sb.toString().endsWith(",")){
			sb.replace(sb.length()-1, sb.length(), "");
		}
		return sb.toString();
	}
	
	public static void main(String[] args){
		String[] a1={"izxm11    \"\"\"\"\"","","jasmine","  "};
		String[] a2={"112346","","112358",""};
		String[] a3={"450584876","","478340340-","  ","",""};
		String content;
		try {
			content = getInsertString(a1,a2,a3);//测试异常抛出
			System.out.println(content);
		} catch (CitrusException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
